<template>
  <div class="login-wrapper">
    <div class="custom-topHr"></div>

    <div class="logo-box">
      <img class="logo" src="@/assets/images/logo1.png">
    </div>
    <div class="login-box">
      <customForm :type="type"/>

      <div class="submit-box">
        <button class="submit-btn" @click="login">提 交</button>

        <!-- <a class="msg-login" href="#">短信验证登录</a> -->

        <p class="privacy-txt">
          <span>登录即代表已经并同意</span>
          <a href="#">《还美医疗整形隐私政策》</a>
        </p>
      </div>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
import customForm from "./form";
import constant from "@/utils/constant.js";
// 引用API文件
import http from "@/utils/http.js";

export default {
  name: "login",
  data() {
    return {
      type: "spreadLogin"
    };
  },
  components: {
    customForm
  },
  created(){
      localStorage.removeItem("user_name");
      localStorage.removeItem("user_head");
      localStorage.removeItem("user_token");
      localStorage.removeItem("user_type");
      console.log('删除localStorage');
      let invite_code = this.$route.query.invite_code;
      console.log(invite_code);
      if(invite_code){
        this.$store.commit("updateRecommend", invite_code);
      }
  },
  methods: {
    login() {
      let username = this.$store.state.loginform.username;
      let mobile = this.$store.state.loginform.mobile;
      let password = this.$store.state.loginform.password;
      let recommend = this.$store.state.loginform.recommend;
      console.log(username);
      console.log(mobile);
      console.log(password);
      console.log(recommend);

      if (username == "") {
        this.$message({
          message: "请填写用户名",
          type: "warning"
        });
      }

      if (mobile == "") {
        this.$message({
          message: "请填写手机号",
          type: "warning"
        });
      }

      if (password == "") {
        this.$message({
          message: "请填写密码",
          type: "warning"
        });
      }

      if (recommend == "") {
        this.$message({
          message: "请填写推广码",
          type: "warning"
        });
      }

      if (username == "" || password == "") {
        this.$message({
          message: "请填写用户名或密码",
          type: "warning"
        });
      } else {
        http.post(this, {
          url: "passport/store_add",
          data: {
            store_name: username,
            store_password: password,
            store_mobile: mobile,
            invite_code: recommend
          },
          dataType: "json",
          success: function(data) {
            console.log("登录:", data);
            if (data.status == 1) {
              this.$router.push({
                //核心语句
                path: "/center"
              });
            } else {
              this.$message.error(data.info);
            }
          }
        });
      }
    }
  }
};
</script>

<style scoped lang="scss">
</style>
